package com.qf.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.entity.ResultHcs;
import com.qf.mapper.UserMapper001;
import com.qf.pojo.Information;
import com.qf.pojo.inforContent;
import com.qf.mapper.InforContentMapper;
import com.qf.pojo.User;
import com.qf.service.InforContentService;
import com.qf.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/infor")
public class InforController {
    @Autowired
    private InformationService informationService;

    @Autowired
    private UserMapper001 userMapper;

    @Autowired
    private InforContentMapper inforContentMapper;

    @Autowired
    private InforContentService inforContentService;

    @PostMapping("/first")
    public ResultHcs test1(){
        String username=(String) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//      System.out.println(username);
//      System.out.println("-----------------------");
        LambdaQueryWrapper<User> qw = new LambdaQueryWrapper<>();
        qw.eq(User::getUsername,username);
        User user = userMapper.selectOne(qw);
        Integer id = user.getId();
//        System.out.println(id);
//        System.out.println("------------------");
        LambdaQueryWrapper<inforContent> qe=new LambdaQueryWrapper<>();
        qe.eq(inforContent::getUserId,id);
        inforContent one1 = inforContentService.getOne(qe);
        Integer uid = one1.getInformationId();
        System.out.println(uid);
        System.out.println("------------------");
        LambdaQueryWrapper<Information> qq = new LambdaQueryWrapper<>();
        qq.eq(Information::getId,uid);
        Information one = informationService.getOne(qq);
        ResultHcs success = ResultHcs.success(one);
        return success;
    }
}
